package com.frogs.ucenter.service.impl;

import java.io.IOException;

import javax.annotation.Resource;

import org.jsoup.Connection;
import org.jsoup.Connection.Method;
import org.jsoup.Jsoup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.frogs.framework.component.cache.Cache;
import com.frogs.ucenter.service.PageService;

/**
 * 用户账号，判断是否登录等。
 * 存储格式为
 * 
 *
 */
@Service("pageService")
public class PageServiceImpl implements PageService{
	
	private static final Logger log = LoggerFactory.getLogger(PageServiceImpl.class);
	
	@Resource(name="xmemcached")
	private Cache cache;

	@Override
	public String getContent(String url) throws IOException {
		Object object = cache.get(url);
		
		if(object != null)
			return object.toString();
		
		Connection.Response res = Jsoup.connect(url)
				.header("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0;)")
				.header("Accept","image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, */*")
			    .method(Method.GET)
			    .ignoreContentType(true)
			    .timeout(50000)
			    .execute();
		String content = res.body();
		
		cache.put(url, content,3600);
		return content;
	}
}
